<div class="row">
	<div class="col-xs-12">
		<div class="box">
			<div class="box-header">
				<h3 class="box-title">日志管理</h3>
				<div class="box-tools">
					<div class="input-group input-group-sm" style="width: 350px;">
						<input type="text" name="table_search" id="searchNameId"
							class="form-control pull-right" placeholder="用户名">

						<div class="input-group-btn">
							<button type="button" class="btn btn-default btn-search">
								<i class="fa fa-search"></i>
							</button>
							<button type="button" class="btn btn-default btn-delete">删除</button>
						</div>
					</div>
				</div>
			</div>
			<!-- /.box-header -->
			<div class="box-body table-responsive no-padding">
				<table class="table table-hover">
					<thead>
						<tr>
							<th><input type="checkbox" id="checkAll">全选</th>
							<th>用户名</th>
							<th>操作</th>
							<th>请求方法</th>
							<th>请求参数</th>
							<th>IP</th>
							<th>执行时长</th>
						</tr>
					</thead>
					<tbody id="tbodyId">
						<tr>
							<td colspan="7">数据正在加载中...</td>
						</tr>
					</tbody>
				</table>
			</div>
			<div id="pageId" class="box-footer clearfix" dm="100"></div>
			<!-- /.box-body -->
		</div>
		<!-- /.box -->
	</div>
</div>
<script type="text/javascript">
	$(function(){
		$("#pageId").load("log/toPage",function(){
			doLoadLogs();
		})
		
		$(".input-group-btn").on("click",".btn-search",doSearch)
							.on("click",".btn-delete",dofindChecked)
		$("#tbodyId").on("change","input[type=checkbox]",doChageBox)
		$("#checkAll").on("click",doCheckAll)
	})
	
	function doCheckAll(){
		var isChecked = $(this).prop("checked");
		$("#tbodyId input[type=checkbox]").prop("checked",isChecked);
	}
	
	function doChageBox(){
		var flag = true;
		$("#tbodyId input[type=checkbox]").each(function(){
			flag = flag & $(this).prop("checked");			
		})
		$("#checkAll").prop("checked",flag);
	}
	
	function dofindChecked(){
		var array = [];
		$("#tbodyId input[type=checkbox]").each(function(){
			var tr = $(this);
			if(tr.prop("checked"))array.push(tr.val());
		})
		dodelete(array);
	}
	
	function dodelete(array){
		$.post("/log/doDeleteObjects",array);
		$("#tbodyId").data("pageCurrent",1);
		doLoadLogs();
	}
	
	function doSearch(){
		var username = $("#searchNameId").val();
		$("#tbodyId").data("username",username);
		$("#tbodyId").data("pageCurrent",1);
		doLoadLogs();
	}
		
		function doLoadLogs(){
			var url = "log/findSysLogs";
			var pageCurrent = $("#tbodyId").data("pageCurrent");
			var username = $("#tbodyId").data("username");
			if(pageCurrent==null)pageCurrent=1;
			var param={"pageCurrent":pageCurrent,"username":username};
			$.getJSON(url,param,function(result){
				if(result.state==1){
					docreateTable(result.data.recodes);
					doInitPage(result.data);
				}else{
					console.log(result.message);
				}
			})
		}
		
		function docreateTable(recodes){
			var tbody= $("#tbodyId");
			tbody.empty();
			recodes.forEach(item=>tbody.append(createTr(item)));
		}
		
		function createTr(item){
			var tr = `<tr>
					<td><input type=checkbox value=${item.id}></td>
					<td>${item.username}</td>
					<td>${item.operation}</td>
					<td>${item.method}</td>
					<td>${item.params}</td>
					<td>${item.time}</td>
					<td>${item.ip}</td>
					</tr>`
			return tr;		
		}
		
		
	
</script>






